X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/2af83e98005a14c439b360a5b9ac636f594d9f0c..38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c:/Super%20Polarity/Actors/Actor.cs diff --git a/Super Polarity/Actors/Actor.cs b/Super Polarity/Actors/Actor.cs index 4351bf2..588ff14 100644 --- a/Super Polarity/Actors/Actor.cs +++ b/Super Polarity/Actors/Actor.cs @@ -12,6 +12,8 @@ namespace SuperPolarity { protected Game game; + public List Children; + // Graphics / In-Game protected Texture2D Texture; protected Vector2 Origin; @@ -21,7 +23,7 @@ namespace SuperPolarity public Vector2 Position; protected Vector2 Velocity; protected Vector2 Acceleration; - protected float Angle; + public float Angle; // Constraints / Behavior protected float MaxVelocity; @@ -48,6 +50,8 @@ namespace SuperPolarity Position = position; Active = true; + Children = new List(); + Origin = new Vector2(Texture.Width / 2, Texture.Height / 2); Velocity = new Vector2(0, 0); Acceleration = new Vector2(0, 0); @@ -115,12 +119,15 @@ namespace SuperPolarity { Move(gameTime); ChangeAngle(); + CheckOutliers(); } - public void Move(GameTime gameTime) + public virtual void Move(GameTime gameTime) { AutoDeccelerate(gameTime); + var maxVelocity = MaxVelocity; + Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds; @@ -155,7 +162,26 @@ namespace SuperPolarity public virtual void Draw(SpriteBatch spriteBatch) { + foreach (Actor child in Children) + { + child.Draw(spriteBatch); + } + spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f); } + + void CheckOutliers() + { + for (var i = Children.Count; i > 0; i--) + { + var actor = Children[i - 1]; + if (actor.Position.X < -SuperPolarity.OutlierBounds || actor.Position.Y < -SuperPolarity.OutlierBounds || + actor.Position.X > game.GraphicsDevice.Viewport.Width + SuperPolarity.OutlierBounds || + actor.Position.Y > game.GraphicsDevice.Viewport.Height + SuperPolarity.OutlierBounds) + { + Children.Remove(actor); + } + } + } } }